package 排序;

import java.util.Arrays;

public class 冒泡排序 {
    // 由小到大
    private static void sort(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            for (int j = 1; j < nums.length - i; j++) {
                if (nums[j] < nums[j - 1]) {
                    int t = nums[j];
                    nums[j] = nums[j - 1];
                    nums[j - 1] = t;
                    // 交换
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] ints = {3, 4, 51, 2, 5, 4576, 3, 4, 234, 7, 89};
        sort(ints);
        System.out.println(Arrays.toString(ints));
    }
}
